using System;
using Science.Mathematics;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter09
{
	/// <summary>
	/// Example15: The Center of Mass of a Right Triangle
	/// You have been asked to hang a metal sign from a single 
	/// vertical wire. The sign has the triangular shape shown 
	/// in Figure 9.23a.(length=a,height=b). The bottom of the sign 
	/// is to be parallel to the ground. 
	/// At what distance from the left end of the 
	/// sign should you attach the support wire?
	/// x_{cm} = 2/3*a
	/// </summary>
	public class Example15
	{
		public Example15()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		double a = 10.0, b = 5.0;
		public void Compute()
		{
			L.Volume volume = new L.Volume();
			volume.XTo = 0.0;
			volume.XFrom = a;
			volume.YTo = 0.0;
			volume.YFrom = b;
			volume.ZTo = 0.0;
			volume.ZFrom = 0.001;
			L.Scalar.FunctionOfPosition func = new L.Scalar.FunctionOfPosition(f);
			L.Density density = new L.Density();
            density.ScalarFunctionOfPosition = func;
			L.CenterOfMass xcm = new L.CenterOfMass(density, volume);
			result+=Convert.ToString(xcm.X);
		}
		private L.Scalar f(L.Position x)
		{
            L.Scalar s = new L.Scalar();
			if(x.Y < b/a*x.X) s.Magnitude = 1.0;
			else s.Magnitude = 0.0;
            return s;
		}
	}
}
